/**
 * @file hoc.jsx.
 * @author liyong18@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from "react";
import {findDOMNode} from 'react-dom';
import {filter} from '../renderer';

import '../form/panel-form';

export const Enhance = ComposedComponent => class DataTipAble extends Component {
  constructor(props, context) {
    super(props, context);

  }

  componentWillReceiveProps(nextProps) {
    const prevEditing = this.props.editing;
    const nextEditing = nextProps.editing;
    const dom = findDOMNode(this.input);
    
    if(!prevEditing && nextEditing && dom) {
      let evt = document.createEvent("MouseEvents");
      evt.initMouseEvent("mousemove", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
      dom.dispatchEvent(evt);
    }
  }

  render() {
    let {
      item,
      tooltip,
      editing,
      popOver
    } = this.props;
    let props = {
      dataTip: !popOver && !editing && tooltip && (filter(tooltip, item))
    };
    return (
      <ComposedComponent ref={input=>this.input = input} {...this.props} {...props} />
    )
  }
};

export default Enhance;